package com.mediacloud.app.newsmodule.activity.audio

import android.content.Context
import android.graphics.Paint
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import androidx.annotation.StyleRes
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.activity.audio.datepicker.DatePickerView
import com.mediacloud.app.newsmodule.activity.audio.datepicker.DatePickerView2

/**
 * @author Heaven Created on 2022/2/22
 */
class TimePickerBottomDialog(context: Context, @StyleRes style: Int, dateResult: ((date: Long) -> Unit)) : BottomSheetDialog(context, style) {

    init {
        val view = View.inflate(context, R.layout.time_picker_dialog_, null)
        val datePicker: DatePickerView2 = view.findViewById(R.id.date_picker)
        datePicker.setCurrentMinute(0,1)
        val title: TextView = view.findViewById(R.id.title)
        title.text = "自定义"
        title.paint.strokeWidth = 1.5f
        title.paint.style = Paint.Style.FILL_AND_STROKE
        val cancel: TextView = view.findViewById(R.id.cancel)
        cancel.setOnClickListener { dismiss() }
        val confirm: TextView = view.findViewById(R.id.confirm)
        confirm.setOnClickListener {
            dateResult.invoke(datePicker.getSelectedDate())
            dismiss()
        }
        val frame: FrameLayout? = delegate.findViewById(com.google.android.material.R.id.design_bottom_sheet)
//        frame?.setBackgroundResource(R.drawable.top_corner_shape)
        setContentView(view)
        setCancelable(true)
        setCanceledOnTouchOutside(true)

        behavior?.setDraggable(false)
    }

    fun showDialog(): TimePickerBottomDialog {
        show()
        return this
    }
}
